#pragma once
#include "Vertex.h"
#include <string>
#include <stack>
#include "SceneNode.h"
#include "SceneRoot.h"
#include "LGrammar.h"
#include "WorldObject.h"


class LTree: public WorldObject
{
public:
		//Tree constructor
	LTree(LGrammar *gr, float deg, Location l, int depth);
		//Copy constructor
	LTree(LTree const &rhs);
		//Assignment operator.
	LTree& operator=(LTree const &rhs);
		//Destructor.
	virtual ~LTree(void);
	
	// WorldObject functions
	virtual SceneRoot* getDrawables(void);
	virtual void update(void);
	virtual int getSize(void);
	virtual Location getLocation(void);
	virtual bool draw(void);
	virtual void setDraw(bool d);
	virtual bool canSplit(void);
	virtual std::list<WorldObject *> split(void);
	virtual bool deleteMe(void);
	virtual void setDelete(bool d);

		//Generates the SceneRoot of the tree.
	void generateTree(void);
		//Returns the generated string for the tree
		//based on its grammar.
	std::string toString(void);
	
private:
	//Helper functions for interpreting the trees.
	void pushNode(void);
	void popNode(void);
	void rotateAlpha(float degree);
	void rotateTheta(float degree);
	void addLeaf(void);
	void addPetal(void);
	void addBranch(void);

	bool deleteThis;
	bool visible;
	Location loc;

	std::string pattern;
	int depth;
	bool generated;
	float degree;
	SceneRoot *root;
	SceneNode *currentNode;
	LGrammar *grammar;
	float curDepth; // Our trees get skinnier!
	std::stack<SceneNode*> nodeStack;
};

SceneRoot* getTestTree(float x, float y, float z);
LTree* getTree(float x, float y, float z);